package com.osfw.dbadminer.enums;

import com.osfw.dbadminer.service.jdbc.impl.DamengJdbcService;
import com.osfw.dbadminer.service.jdbc.impl.MysqlJdbcService;
import com.osfw.dbadminer.service.jdbc.impl.PostgresqlJdbcService;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 连接（数据库）类型 枚举类
 */
public enum ConnectType {

    MYSQL("mysql", "MySQL",  "", MysqlJdbcService.class),
    POSTGRESQL("postgresql", "PostgreSQL",  "", PostgresqlJdbcService.class),
    DAMENGSQL("dameng", "DaMeng",  "", DamengJdbcService.class),
    H2("h2", "H2",  "", null);

    private String type;
    private String name;
    private String icon;
    private Class clz;

    ConnectType(String type, String name, String icon, Class clz) {
        this.type = type;
        this.name = name;
        this.icon = icon;
        this.clz = clz;
    }

    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    public String getIcon() {
        return icon;
    }

    public Class getClz() {
        return clz;
    }

    public static Class getClzByType(String type) {
        for (ConnectType typeEnum : values()) {
            if (typeEnum.getType().equals(type)) {
                return typeEnum.getClz();
            }
        }
        return null;
    }

    public static Map<String, Class> getConnectTypeList() {
        HashMap<String, Class> map = new LinkedHashMap<>();
        for (ConnectType typeEnum : values()) {
            map.put(typeEnum.getType(), typeEnum.getClz());
        }
        return map;
    }

}
